package com.sjl.sophixdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.sjl.sophixdemo.util.JNIUtil;
import com.sjl.testlibrary.LibUtil;
import com.taobao.sophix.SophixManager;

public class MainActivity extends Activity implements View.OnClickListener {

    private Button btnLoad;
    private Button btnClear;
    private Button btnJava;
    private Button btnLib;
    private Button btnJNI;
    private Button btnImg;
    private ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
    }

    private void initView() {
        btnLoad = (Button) findViewById(R.id.btnLoad);
        btnLoad.setOnClickListener(this);
        btnClear = (Button) findViewById(R.id.btnClear);
        btnClear.setOnClickListener(this);
        btnJava = (Button) findViewById(R.id.btnJava);
        btnJava.setOnClickListener(this);
        btnLib = (Button) findViewById(R.id.btnLib);
        btnLib.setOnClickListener(this);
        btnJNI = (Button) findViewById(R.id.btnJNI);
        btnJNI.setOnClickListener(this);
        btnImg = (Button) findViewById(R.id.btnImg);
        btnImg.setOnClickListener(this);
        iv = (ImageView) findViewById(R.id.iv);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnLoad:
                SophixManager.getInstance().queryAndLoadNewPatch();
                break;
            case R.id.btnClear:
                SophixManager.getInstance().cleanPatches();
                break;
            case R.id.btnJava:
//                toast("java");
                toast("java fix");
                break;
            case R.id.btnLib:
                toast(LibUtil.getText());
                break;
            case R.id.btnJNI:
                toast(JNIUtil.stringFromJNI());
                break;
            case R.id.btnImg:
                //saber图片是新app添加进来的
//                iv.setImageResource(R.mipmap.ic_launcher);
                iv.setImageResource(R.mipmap.saber);
                break;
        }
    }

    private void toast(String text) {
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
    }

}
